﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mvc.XForms.Actions;

namespace Mvc.XForms.Controls.Settings {
	public class TextAreaSettings {
		public ITextArea TextArea { get; set; }

		public TextAreaSettings(ITextArea textArea) {
			TextArea = textArea;
		}

		public TextAreaSettings Label(string label) {
			TextArea.Label = label;
			return this;
		}

		public TextAreaSettings Help(string help) {
			TextArea.Help = help;
			return this;
		}

		public TextAreaSettings Hint(string hint) {
			TextArea.Hint = hint;
			return this;
		}

		public TextAreaSettings Appearance(Appearance appearance) {
			TextArea.Appearance = appearance;
			return this;
		}

		public TextAreaSettings ReadOnly() {
			return ReadOnly(true);
		}

		public TextAreaSettings ReadOnly(bool readOnly) {
			TextArea.ReadOnly = readOnly;
			if (readOnly)
				TextArea.CssClass.Add("readonly");
			return this;
		}

		public TextAreaSettings Required() {
			return Required(true);
		}

		public TextAreaSettings Required(bool required) {
			TextArea.Required = required;
			if (required)
				TextArea.CssClass.Add("required");
			return this;
		}

		public TextAreaSettings ID(string clientID) {
			TextArea.ClientID = clientID;
			return this;
		}

		public TextAreaSettings CssClass(string cssClass) {
			TextArea.CssClass.Add(cssClass);
			return this;
		}

		public TextAreaSettings Rows(int rows) {
			TextArea.Rows = rows;
			return this;
		}

		public TextAreaSettings Columns(int columns) {
			TextArea.Columns = columns;
			return this;
		}

		public TextAreaSettings Action(XFormEvent xformsEvent, string jsFunction) {
			var action = new ActionAction() {
				Event = xformsEvent,
				JSFunction = jsFunction
			};
			TextArea.Actions.Add(action);
			return this;
		}

		public override string ToString() {
			return TextArea.ValidateThenRender();
		}
	}
}
